package _interview75;

/**
 * 338. 比特位计数
 */
public class No338 {
    public int[] countBits(int n) {
        int[] ans = new int[n + 1];
        for (int i = 0; i <= n; i++) {
            int curSum = 0;
            for (int j = 0; j < 32; j++) {
                curSum += i >> j & 1;
            }
            ans[i] = curSum;
        }
        return ans;
    }
}
